﻿using BookShopWeb.Models.DB;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Book.Controllers
{
    public class HomeController : Controller
    {
        BookShopContext db = new BookShopContext();
        public ActionResult Index()
        {
            List<IndexBooks> indexBooks = new List<IndexBooks>();
            List<NewBooks> d = db.NewBooks.FromSqlRaw("SELECT TOP (5) [Title],[Name],[Price],[Discount],[Photo] FROM [NewBooks] Order By [BookID] desc").ToList();
            List<NewBooks> newB = db.NewBooks.FromSqlRaw("SELECT TOP (5) [Title],[Name],[Price],[Discount],[Photo] FROM [NewBooks] Order By [BookID] desc").ToList();
            List<SalesHitsBooks> hits = db.SalesHitsBooks.FromSqlRaw("SELECT TOP (5) [BookID],[Title],[Price],[Discount],[Name],[Photo],[CountSales] FROM [BookShop].[dbo].[SalesHitsBooks] Order by [CountSales] Desc").ToList();
            for (int i = 0; i < 5; i++)
            {
                indexBooks.Add(new IndexBooks());
                indexBooks[i].NewBooks = newB[i];
                indexBooks[i].SalesHitsBooks = hits[i];
            }

            return View(indexBooks);
        }

        public ActionResult Privacy()
        {
            return View();
        }
        public ActionResult Error()
        {
            return View();
        }
    }
}